<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta content="IE=edge" http-equiv="X-UA-Compatible">
    <meta content="width=device-width, initial-scale=1" name="viewport">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>商品添加</title>
    <!-- Bootstrap -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- HTML5 shim 和 Respond.js 是为了让 IE8 支持 HTML5 元素和媒体查询（media queries）功能 -->
    <!-- 警告：通过 file:// 协议（就是直接将 html 页面拖拽到浏览器中）访问页面时 Respond.js 不起作用 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
    <![endif]-->
    <link href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <!--    引入首页样式-->
    <link href="admin/favicon.ico" rel="shortcut icon" />
    <link href="../indexCss.css" rel="stylesheet" type="text/css">
    <style>
        body {
            padding: 0;
            margin: 0;
            position: relative;
            color: rgba(0, 0, 0, 0.68)
        }

        a {
            color: rgba(0, 0, 0, 0.68);
            cursor: pointer; /*加手图标*/
            text-decoration: none;
        }

        a:hover {
            color: #24407EAD;
        }



        section>div{
            margin: 0;
            padding: 0;
            /*background-color: rgba(119, 113, 113, 0.32);*/
        }
    </style>
</head>
<body>
<myheader></myheader>




<section>
    <div class="container" >
    <div class="row col-md-12"  style=" position:relative;top:60px;padding: 20px;">
                <div class="col-md-3 " style="width: 250px;">
                    <mydiv v-bind:cls="cls" v-bind:com="com" v-bind:rcls="rcls" v-bind:rep="rep"></mydiv>
                </div>
                 <div class="col-md-2"></div><!--为了中间间隔点-->
                <div class="col-md-7" >
                        <form enctype="multipart/form-data" role="form" style="padding: 50px 20px;background-color: rgb(255,255,255);">
                            <div class="form-group">
                                <label>商品名</label><input class="form-control" name="name"
                                                         type="text"
                            >
                            </div>
                            <div class="form-group">
                                <label>库存</label><input class="form-control" name="sum"
                                                        type="text"
                            >

                            </div>
                            <div class="form-group">
                                <label>价格</label><input class="form-control" name="price"
                                                        type="text"
                                                        >
                            </div>
                            <div class="form-group">
                                <label>产品说明</label><input class="form-control" name="intro"
                                                          type="text"
                            >
                            </div>
                            <!--                            <div class="form-group">-->
                            <!--                                <label>所属产品类</label><input type="password"-->
                            <!--                                                          class="form-control"-->
                            <!--                                                          />-->
                            <!--                            </div>-->
                            <div class="form-group">
                                <input id="exampleInputFile" name="picFile" type="file"/>
                                <p class="help-block">
                                    请选择您所要上架的商品图片
                                </p>
                            </div>
                            <div class="item item-input item-select">
                                <label>请选择所属产品类</label>
                                <select  name="classId">
                                    <option >请选择</option>
                                    <option :value="c.id" v-for="c in cls">{{c.name}}</option>
                                </select>
                                <div style="float: right">
                                    <button @click="send" class="btn btn-success"  type="button">确认添加</button>
                                </div>
                            </div>

                        </form>
                </div>

    </div>
    </div>
</section>

<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
<script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
<!--引入vue和axios-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script>
    let v = new Vue({
        el:"section",
        data:{
            cls: {}, //类集合
            com: {}, //商品集合
            rcls: [], //资讯类集合
            rep: [], //资讯集合
            id:"",
        },
        created:function(){
            axios.post("/admin/selectToClass").then(function (response) {
                v.cls = response.data;
                axios.post("/admin/selectToCommodity").then(function (response) {
                    v.com = response.data;
                })
                axios.post("/admin/selectToReportCls").then(function (response) {
                    v.rcls = response.data;
                })
                axios.post("/admin/selectToReport").then(function (response) {
                    v.rep = response.data;
                })
            })
        },
        methods:{
            send:function (){
                let data = new FormData(document.querySelector("form"))
                if (confirm("您确认添加嘛?")) {
                    // if (data.get("classId") == "请选择") {
                    //     alert("请选择分类!!!");
                    //     return;
                    // }
                    // if (data.get("picFile").name == "") {
                    //     alert("请上传文件!");
                    //     return;
                    // }
                    //发请求
                    axios.post("/admin/commodityinsert", data).then(function () {
                        // if (response.data==1){

                        //发布成功跳回首页
                        // location.href="/admin-product.html";
                        // }else {
                        //     alert("请先登录!");
                        //     location.href="/login.html";
                        // }
                    })
                }
            }
        }
    })

</script>
<script src="adminjs/mydiv.js"></script>
<!--<script>-->
<!--    var mydiv_v = new Vue({-->
<!--        el: "#mydiv1",-->
<!--        data:{-->
<!--            cls: {}, //类集合-->
<!--            com: {}, //商品集合-->
<!--            rcls: [], //资讯类集合-->
<!--            rep: [], //资讯集合-->
<!--            id:"",-->
<!--        },-->
<!--        created:function(){-->
<!--            axios.post("/admin/selectToClass").then(function (response) {-->
<!--                mydiv_v.cls = response.data;-->
<!--                axios.post("/admin/selectToCommodity").then(function (response) {-->
<!--                    mydiv_v.com = response.data;-->
<!--                })-->
<!--                axios.post("/admin/selectToReportCls").then(function (response) {-->
<!--                    mydiv_v.rcls = response.data;-->
<!--                })-->
<!--                axios.post("/admin/selectToReport").then(function (response) {-->
<!--                    mydiv_v.rep = response.data;-->
<!--                })-->
<!--            })-->
<!--        }-->
<!--    })-->
<!--</script>-->
<!--引入footer-->
<!--<script src="adminjs/footer.js"></script>-->
<!--引入header-->
<script src="adminjs/header.js"></script>
<!--引入mydiv  左侧导航栏-->

<!--背景线条-->
<script src="https://cdn.bootcss.com/canvas-nest.js/1.0.1/canvas-nest.min.js" type="text/javascript"></script>　
<!--右键出字体-->
<script src="adminjs/bgfont.js"></script>　
</body>
</html>